#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;

struct Person{
    char name[10];
    int age;
    int worth;
};

vector<Person*> persons;
int N;
int K;
bool msort(const Person* a,const Person* b){
    if(a->worth==b->worth){
        if(a->age==b->age){
            return strcmp(a->name,b->name)<0;
        }
        return a->age<=b->age;
    }
    return a->worth>=b->worth;
}
int main(){
    scanf("%d %d",&N,&K);
    int i=0;
    while(i++<N){
        Person* person = new Person();
        scanf("%s %d %d",(person->name),&(person->age),&(person->worth));
        persons.push_back(person);
    }
    sort(persons.begin(),persons.end(),msort);
    //for(i=0;i<persons.size();++i){
    //    printf("%s %d %d\n",persons[i]->name,persons[i]->age,persons[i]->worth);
    //}
    i=0;
    int M,Amin,Amax;
    while(i++<K){
        scanf("%d %d %d",&M,&Amin,&Amax);
        printf("Case #%d:\n",i);
        int cnt=0;
        for(int j=0;j<persons.size();j++){
            if(persons[j]->age>=Amin&&persons[j]->age<=Amax){
                cnt++;
                printf("%s %d %d\n",persons[j]->name,persons[j]->age,persons[j]->worth);
            }
            if(cnt>=M) break;
        }
        if(cnt==0)
            printf("None\n");
    }
    return 0;
}
